#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include"Common.hpp"

int main()
{
    umask(0);

    if(mkfifo("tp",0644)<0)
    {
        ERR_EXIT("mkfifo");
    }

    int rfd = open("tp",O_RDONLY);
    if(rfd<0) ERR_EXIT("open");

    char buf[1024];
    while(1)
    {
        buf[0] = 0;
        printf("Please wait...");
        ssize_t s = read(rfd,buf,sizeof(buf)-1);
        if(s>0) 
        {
            buf[s]=0;
            printf("client say: %s\n",buf);
        }
        else if(s==0)
        {
            printf("client quit,exit now!\n");
            exit(EXIT_SUCCESS);
        }
        else
        {
            ERR_EXIT("read");
        }
    }

    close(rfd);

    return 0;

}